<template>
  <div class="box">
    <h2>Son1 子组件</h2>
    从vuex中获取的值: <label>{{ $store.state.count }}</label>
    <br>
    <button @click="handleAdd">值 + 1</button>
    <button @click="handleAdd5">值 + 5</button>
    <button @click="handleChangeTittle">该标题</button>
    <button @click="handleAdd10(10)">值 + 10</button>
    <button @click="changeTittle2('自定义标题')">自定义标题</button>

  </div>
</template>

<script>
export default {
  name: 'Son1Com',
  methods: {
    handleAdd() {
      // 错误代码,不符和单向数据流规范,vue默认不会检测
      // this.$store.state.count++
      
      //调用 mutations 中的方法
      this.$store.commit('addCount')
    },
    handleAdd5() {
      this.$store.commit('addFive')
    },
    handleChangeTittle() {
      this.$store.commit('changeTittle')
    },
    handleAdd10 (num) {
      this.$store.commit('addCount2', num)
    },
    changeTittle2(newTitle) {
      this.$store.commit('changeTittle2', newTitle)
    }
  }
}
</script>

<style lang="css" scoped>
.box{
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>
